package com.xxl.job.core.util;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;

/**
 * @author lisicheng
 * @date 2022-08-10
 */
public class DingtalkUtil {

  private static final String URL =
      "https://oapi.dingtalk.com/robot/send?access_token=ed1241ccb83d46e2203e2affe17690c74e672ecd4c8447b6ce2f767a8ae3b80f";

  public static void send(String title, String content) {
    String template = "预警：\n{}\n{}";
    HttpUtil.post(URL,
        JSONUtil.toJsonStr(new Body(new Text(StrUtil.format(template, title, content)))));
  }

  private static class Body {

    private String msgtype = "text";

    private Text text;

    Body(Text text) {
      this.text = text;
    }

    public String getMsgtype() {
      return this.msgtype;
    }

    public Text getText() {
      return text;
    }
  }


  private static class Text {

    private String content;

    Text(String content) {
      this.content = content;
    }

    public String getContent() {
      return content;
    }
  }

}
